export default function ReferencePage() {
  return (
    <div className="container mx-auto py-10 px-4">
      <h1 className="text-3xl font-bold mb-6">PostgreSQL 参考文档</h1>

      <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
        <div className="space-y-4">
          <h2 className="text-xl font-semibold">基本查询</h2>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">SELECT</h3>
            <p className="text-sm text-muted-foreground mt-1">从表中检索数据</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`SELECT column1, column2, ...
FROM table_name
WHERE condition;`}
            </pre>
          </div>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">INSERT</h3>
            <p className="text-sm text-muted-foreground mt-1">向表中插入数据</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);`}
            </pre>
          </div>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">UPDATE</h3>
            <p className="text-sm text-muted-foreground mt-1">更新表中的数据</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;`}
            </pre>
          </div>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">DELETE</h3>
            <p className="text-sm text-muted-foreground mt-1">删除表中的数据</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`DELETE FROM table_name
WHERE condition;`}
            </pre>
          </div>
        </div>

        <div className="space-y-4">
          <h2 className="text-xl font-semibold">表操作</h2>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">CREATE TABLE</h3>
            <p className="text-sm text-muted-foreground mt-1">创建新表</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`CREATE TABLE table_name (
  column1 datatype constraints,
  column2 datatype constraints,
  ...
);`}
            </pre>
          </div>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">ALTER TABLE</h3>
            <p className="text-sm text-muted-foreground mt-1">修改表结构</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`-- 添加列
ALTER TABLE table_name
ADD column_name datatype;

-- 删除列
ALTER TABLE table_name
DROP COLUMN column_name;`}
            </pre>
          </div>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">DROP TABLE</h3>
            <p className="text-sm text-muted-foreground mt-1">删除表</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`DROP TABLE table_name;`}
            </pre>
          </div>
        </div>

        <div className="space-y-4">
          <h2 className="text-xl font-semibold">高级查询</h2>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">JOIN</h3>
            <p className="text-sm text-muted-foreground mt-1">连接多个表</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`-- 内连接
SELECT a.column1, b.column2
FROM table_a a
INNER JOIN table_b b ON a.common_field = b.common_field;

-- 左连接
SELECT a.column1, b.column2
FROM table_a a
LEFT JOIN table_b b ON a.common_field = b.common_field;`}
            </pre>
          </div>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">GROUP BY</h3>
            <p className="text-sm text-muted-foreground mt-1">分组数据</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`SELECT column1, COUNT(*)
FROM table_name
GROUP BY column1;`}
            </pre>
          </div>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">HAVING</h3>
            <p className="text-sm text-muted-foreground mt-1">过滤分组后的结果</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`SELECT column1, COUNT(*)
FROM table_name
GROUP BY column1
HAVING COUNT(*) > 5;`}
            </pre>
          </div>

          <div className="border rounded-md p-4">
            <h3 className="font-medium">子查询</h3>
            <p className="text-sm text-muted-foreground mt-1">嵌套查询</p>
            <pre className="text-xs mt-2 bg-muted p-2 rounded overflow-x-auto">
              {`SELECT column1
FROM table_name
WHERE column2 IN (
  SELECT column2
  FROM another_table
  WHERE condition
);`}
            </pre>
          </div>
        </div>
      </div>
    </div>
  );
} 